import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Decoder {
	protected static final Pattern instruction = Pattern.compile("^([0-1]{2})([0-1]{6})([0-1]{24})$");
	private Matcher myMatcher = instruction.matcher("nullString"); 

	public void decodeInstruction(Instruction i) {
		myMatcher.reset(i.getInstruction());
		if(myMatcher.matches()){
			if(myMatcher.group(1).equals("00")){				
				i.setType(Instruction.Type.ARITHMETIC);
			}
			else if(myMatcher.group(1).equals("01")){				
				i.setType(Instruction.Type.BRANCH);
			}
			else if(myMatcher.group(1).equals("10")){

				i.setType(Instruction.Type.JUMP);
			}
			else if(myMatcher.group(1).equals("11")){				
				i.setType(Instruction.Type.IO);
			}			
		}		
	}
}
